﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Web.Security" %>
<%@ import Namespace="RobozzleModel" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="System.Collections.Generic" %>

<script runat="server">
  void Register_Click(object sender, EventArgs e)
  {
      string error = new RobozzleService().RegisterUser2(
          UserName.Text, StatsCommon.HashPassword(UserPass.Text),
          UserEmail.Text, new Dictionary<int, string>());
      
      if (error == null)
      {
          FormsAuthentication.RedirectFromLoginPage(UserName.Text, true);
      }
      else
      {
          Msg.Text = error;
      }
  }
</script>

<html>
<head id="Head1" runat="server">
  <title>RoboZZle Registration</title>
    <link href="stats.css" rel="stylesheet" type="text/css"/>  
</head>
<body>
  <form id="form1" runat="server">
    <h1>RoboZZle Registration</h1>
    <asp:Label ID="Label1" ForeColor="red" runat="server" />
    <table>
      <tr>
        <td>Username:</td>
        <td>
            <asp:TextBox ID="UserName" runat="server" />
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" 
                ControlToValidate="UserName"
                Display="Dynamic" 
                ErrorMessage="Field cannot be empty." 
                runat="server" />
                
             <asp:RegularExpressionValidator 
               id="RegularExpressionValidator1" runat="server" 
               Display="Dynamic"               
               ControlToValidate="UserName" 
               ErrorMessage="Username must be 4-14 alphanumeric characters."
               ValidationExpression="[a-zA-Z0-9_]{4,14}">
             </asp:RegularExpressionValidator>                
        </td>
      </tr>
      <tr>
        <td>Password:</td>
        <td>
            <asp:TextBox ID="UserPass" TextMode="Password" runat="server" />
        </td>
        <td>            
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" 
                ControlToValidate="UserPass"
                ErrorMessage="Field cannot be empty."
                Display="Dynamic" 
                runat="server" />
             <asp:RegularExpressionValidator 
               id="RegularExpressionValidator2" runat="server" 
               Display="Dynamic"               
               ControlToValidate="UserPass" 
               ErrorMessage="Password must be 4-20 characters."
               ValidationExpression="[a-zA-Z0-9_]{4,20}">
             </asp:RegularExpressionValidator>                  
        </td>
      </tr>
      <tr>
        <td>Repeat Password:</td>
        <td>
            <asp:TextBox ID="UserPass2" TextMode="Password" runat="server" />
        </td>
        <td>            
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" 
                ControlToValidate="UserPass2"
                ErrorMessage="Field cannot be empty." 
                Display="Dynamic"
                runat="server" />        
            <asp:CompareValidator 
                ID="CompareValidator1" runat="server" 
                ErrorMessage="Passwords don't match." 
                Display="Dynamic"
                ControlToValidate="UserPass2" 
                ControlToCompare="UserPass" />
        </td>
      </tr>
      <tr>
        <td>Email:</td>
        <td>
            <asp:TextBox ID="UserEmail" runat="server" />
        </td>
        <td>
        </td>
      </tr>         
      <tr>
        <td colspan="3"><asp:Button ID="Submit1" OnClick="Register_Click" Text="Register" runat="server" /></td>
      </tr>
    </table>
    <p><asp:Label ID="Msg" ForeColor="red" runat="server" /></p>
  </form>
<%= StatsCommon.Footer() %>
</body>
</html>
